package com.example.gaoyang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.gaoyang.domain.request.SysRoleRequest;
import com.example.gaoyang.domain.vo.SysRoleVO;
import com.example.gaoyang.request.Result;
import com.example.gaoyang.service.SysRoleService;
import com.example.gaoyang.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @PostMapping("/addSysRole")
    public Result addSysRole(@RequestBody SysRoleRequest sysRoleRequest) {
        sysRoleService.addSysRole(sysRoleRequest);
        return ResultUtil.success(String.format("角色创建成功,角色名:[%s]", sysRoleRequest.getRoleName()));
    }

    @PostMapping("/addRoleAndElement")
    public Result addRoleAndElement(@RequestBody SysRoleRequest sysRoleRequest) {
        sysRoleService.addRoleAndElement(sysRoleRequest);
        return ResultUtil.success(String.format("角色创建成功,角色名:[%s]", sysRoleRequest.getRoleName()));
    }

    @PostMapping("/removeSysRole")
    public Result removeSysRole(@RequestBody SysRoleRequest sysRoleRequest) {
        sysRoleService.removeSysRole(sysRoleRequest);
        return ResultUtil.success(String.format("角色删除成功,角色id:[%s]", sysRoleRequest.getId()));
    }

    @PostMapping("/removeRoleAndElement")
    public Result removeRoleAndElement(@RequestBody SysRoleRequest sysRoleRequest) {
        sysRoleService.removeRoleAndElement(sysRoleRequest);
        return ResultUtil.success(String.format("角色删除成功,角色id:[%s]", sysRoleRequest.getId()));
    }

    @PostMapping("/getSysRoleList")
    public Result<List<SysRoleVO>> getSysRoleList(@RequestBody SysRoleRequest sysRoleRequest) {
        return ResultUtil.success(sysRoleService.getSysRoleList(sysRoleRequest));
    }

    @PostMapping("/getSysRolePage")
    public Result getSysRoleListPage(Page page, @RequestBody SysRoleRequest sysRoleRequest) {
        return ResultUtil.success(sysRoleService.getSysRolePage(page, sysRoleRequest));
    }

    @PostMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRoleRequest sysRoleRequest) {
        sysRoleService.updateSysRole(sysRoleRequest);
        return ResultUtil.success(String.format("角色修改成功,角色id:[%s]", sysRoleRequest.getId()));
    }

    @PostMapping("/updateRoleAndElement")
    public Result updateRoleAndElement(@RequestBody SysRoleRequest sysRoleRequest) {
        sysRoleService.updateRoleAndElement(sysRoleRequest);
        return ResultUtil.success(String.format("角色修改成功,角色id:[%s]", sysRoleRequest.getId()));
    }

}
